wayland: Postpone processing move_to_rect params until showing
authorJonas Ådahl <jadahl@gmail.com>
Mon, 8 Aug 2016 07:00:42 +0000 (15:00 +0800)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 18 Aug 2016 08:52:03 +0000 (04:52 -0400)
At the time of move_to_rect() is called, not all state may have been set
up on the impl gdk window, causing the position to sometimes be
slightly offset due to drap shadow margins. For now, work around this
by postponing the processing of the move_to_rect() parameters until
showing, when its more likely that all state (such as shadow margin)
has been set correctly.

https://bugzilla.gnome.org/show_bug.cgi?id=769402

gdk/wayland/gdkwindow-wayland.c

index 193d8cdff49e7396656d6b95e6089a4c2904abdc..e267294698f4c73a94d86028cf3db6abaabd75c9 100644 (file)
@@ -126,6 +126,7 @@ struct _GdkWindowImplWayland
   unsigned int pending_commit : 1;
   unsigned int awaiting_frame : 1;
   unsigned int position_set : 1;
+  unsigned int moved_to_rect : 1;
   GdkWindowTypeHint hint;
   GdkWindow *transient_for;
 
@@ -172,6 +173,15 @@ struct _GdkWindowImplWayland
   int saved_height;
 
   gulong parent_surface_committed_handler;
+
+  struct {
+    GdkRectangle rect;
+    GdkGravity rect_anchor;
+    GdkGravity window_anchor;
+    GdkAnchorHints anchor_hints;
+    gint rect_anchor_dx;
+    gint rect_anchor_dy;
+  } pending_move_to_rect;
 };
 
 struct _GdkWindowImplWaylandClass
@@ -1702,6 +1712,20 @@ gdk_wayland_window_show (GdkWindow *window,
 {
   GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
 
+  if (impl->moved_to_rect)
+    {
+      GdkWindowImplClass *impl_class =
+        GDK_WINDOW_IMPL_CLASS (_gdk_window_impl_wayland_parent_class);
+
+      impl_class->move_to_rect (window,
+                                &impl->pending_move_to_rect.rect,
+                                impl->pending_move_to_rect.rect_anchor,
+                                impl->pending_move_to_rect.window_anchor,
+                                impl->pending_move_to_rect.anchor_hints,
+                                impl->pending_move_to_rect.rect_anchor_dx,
+                                impl->pending_move_to_rect.rect_anchor_dy);
+    }
+
   if (!impl->display_server.wl_surface)
     gdk_wayland_window_create_surface (window);
 
@@ -1916,6 +1940,7 @@ gdk_window_wayland_move_resize (GdkWindow *window,
           window->x = x;
           window->y = y;
           impl->position_set = 1;
+          impl->moved_to_rect = 0;
 
           if (impl->display_server.wl_subsurface)
             {
@@ -1932,6 +1957,33 @@ gdk_window_wayland_move_resize (GdkWindow *window,
     gdk_wayland_window_maybe_configure (window, width, height, impl->scale);
 }
 
+static void
+gdk_window_wayland_move_to_rect (GdkWindow          *window,
+                                 const GdkRectangle *rect,
+                                 GdkGravity          rect_anchor,
+                                 GdkGravity          window_anchor,
+                                 GdkAnchorHints      anchor_hints,
+                                 gint                rect_anchor_dx,
+                                 gint                rect_anchor_dy)
+{
+  GdkWindowImplWayland *impl = GDK_WINDOW_IMPL_WAYLAND (window->impl);
+
+  /*
+   * Various state (such as the shadow margin) may be incorrect at this point,
+   * so wait until showing before actually trying to move according to the
+   * anchors and hints.
+   */
+
+  impl->moved_to_rect = 1;
+
+  impl->pending_move_to_rect.rect = *rect;
+  impl->pending_move_to_rect.rect_anchor = rect_anchor;
+  impl->pending_move_to_rect.window_anchor = window_anchor;
+  impl->pending_move_to_rect.anchor_hints = anchor_hints;
+  impl->pending_move_to_rect.rect_anchor_dx = rect_anchor_dx;
+  impl->pending_move_to_rect.rect_anchor_dy = rect_anchor_dy;
+}
+
 static void
 gdk_window_wayland_set_background (GdkWindow       *window,
                                    cairo_pattern_t *pattern)
@@ -2832,6 +2884,7 @@ _gdk_window_impl_wayland_class_init (GdkWindowImplWaylandClass *klass)
   impl_class->restack_under = gdk_window_wayland_restack_under;
   impl_class->restack_toplevel = gdk_window_wayland_restack_toplevel;
   impl_class->move_resize = gdk_window_wayland_move_resize;
+  impl_class->move_to_rect = gdk_window_wayland_move_to_rect;
   impl_class->set_background = gdk_window_wayland_set_background;
   impl_class->reparent = gdk_window_wayland_reparent;
   impl_class->set_device_cursor = gdk_window_wayland_set_device_cursor;